package com.psp.web.netease;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

public class Test {
	public static void main(String[] args) throws Exception {
		DefaultHttpClient httpClient = new DefaultHttpClient();
		String url = "https://api.netease.im/nimserver/user/create.action";
		HttpPost httpPost = new HttpPost(url);

		String appKey = "0122e119de19a63125fd1de683bc9503";
		String appSecret = "f4300b0489af";
		String nonce = "123456";
		String curTime = String.valueOf((new Date()).getTime() / 1000L);
		String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce, curTime);// 参考
																					// 计算CheckSum的java代码

		// 设置请求的header
		httpPost.addHeader("AppKey", appKey);
		httpPost.addHeader("Nonce", nonce);
		httpPost.addHeader("CurTime", curTime);
		httpPost.addHeader("CheckSum", checkSum);
		httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");

		// 设置请求的参数
		List<NameValuePair> nvps = new ArrayList<NameValuePair>();
//		nvps.add(new BasicNameValuePair("accid", "a453b4a8b8bd46179c56966333b8ab3f"));
//		nvps.add(new BasicNameValuePair("name", "未命名54383"));
//		nvps.add(new BasicNameValuePair("token", "123456"));

//		nvps.add(new BasicNameValuePair("accid", "28f475e22e9346559c530ded4dd8d70a"));
//		nvps.add(new BasicNameValuePair("name", "靳春城"));
//		nvps.add(new BasicNameValuePair("token", "123456"));

//		nvps.add(new BasicNameValuePair("accid", "f6edc55919234004a3116c3e9a598360"));
//		nvps.add(new BasicNameValuePair("name", "王欣"));
//		nvps.add(new BasicNameValuePair("token", "123456"));

//		nvps.add(new BasicNameValuePair("accid", "f8613f3b1cd242da8518f572f8f63773"));
//		nvps.add(new BasicNameValuePair("name", "未命名nostr"));
//		nvps.add(new BasicNameValuePair("token", "123456"));

//		nvps.add(new BasicNameValuePair("accid", "6a7e87046b8947f4b1702fa478262ca3"));
//		nvps.add(new BasicNameValuePair("name", "未魏伟"));
//		nvps.add(new BasicNameValuePair("token", "123456"));

//		nvps.add(new BasicNameValuePair("accid", "a59928b4985846679464a1b793bb9a55"));
//		nvps.add(new BasicNameValuePair("name", "程蕾"));
//		nvps.add(new BasicNameValuePair("token", "123456"));

//		nvps.add(new BasicNameValuePair("accid", "3c50975ddc4940a0b840b59621043826"));
//		nvps.add(new BasicNameValuePair("name", "王抗抗"));
//		nvps.add(new BasicNameValuePair("token", "123456"));

//		nvps.add(new BasicNameValuePair("accid", "800f6b8d71dc4995970b9d60cd1875af"));
//		nvps.add(new BasicNameValuePair("name", "杜雨飞"));
//		nvps.add(new BasicNameValuePair("token", "123456"));

//		nvps.add(new BasicNameValuePair("accid", "b1546e48465d4f6b9de42063cac7b10e"));
//		nvps.add(new BasicNameValuePair("name", "加速度"));
//		nvps.add(new BasicNameValuePair("token", "123456"));

//		nvps.add(new BasicNameValuePair("accid", "715f8d80571b41dd86ec8b956c3a7acb"));
//		nvps.add(new BasicNameValuePair("name", "示范点"));
//		nvps.add(new BasicNameValuePair("token", "123456"));

		httpPost.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));

		// 执行请求
		HttpResponse response = httpClient.execute(httpPost);

		// 打印执行结果
		System.out.println(EntityUtils.toString(response.getEntity(), "utf-8"));
	}
}